package com.msgqu.share.exception;

import com.msgqu.share.domain.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @description:
 * @author: wsj
 * @create: 2020-11-25 18:16
 * @throws:
 */
@Slf4j
@RestControllerAdvice
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler({SharedException.class})
    public ResponseEntity<Result> handlerException(SharedException e){
        return ResponseEntity.status(e.getResult().getCode()).body(e.getResult());
    }
    @ExceptionHandler({Exception.class})
    public ResponseEntity<Result> methodArgumentNotValidHandler(Exception e){
        log.error("-------->全局未捕获的异常！",e);
        return ResponseEntity.status(500).body(Result.fail("系统异常！"));
    }
}
